/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.knezevic.realestate.beans;

import com.knezevic.realestate.Member;
import com.knezevic.realestate.Privilege;
import com.knezevic.realestate.service.Members;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;

/**
 *
 * @author Nemanja
 */
public class MembersServiceBean implements Members{

    HashMap<Long, Member> members;

    public MembersServiceBean(HashMap<Long, Member> members) {
        super();
        this.members = members;
    }
    public MembersServiceBean() {
        this(new HashMap<Long, Member>());
    }



    public Member save(Member member) {
//        members.put(member.getID(), member);
//        return members.get(member.getID());
        return member;
    }

    public void update(Member member) {
//        members.remove(member.getID());
//        members.put(member.getID(), member);
    }

    public void deleteMember(Member member) {
//         members.remove(member.getID());
    }

    public Collection<Member> retrieve() {
        return members.values();
    }

    public Collection<Member> retrieveRegularMembers() {
        List<Member> regularMembers = new ArrayList<Member>();
        for (Member member : retrieve()) {
            if(member.getPrivilege().equals(Privilege.REGULAR)){
                regularMembers.add(member);
            }
        }return regularMembers;
    }

    public Member retrieve(Serializable id) {
        return members.get(id);

    }

}
